<?php

namespace App\HttpController;

use EasySwoole\Core\Component\Pool\PoolManager;

/**
 * Class Index
 * @package App\HttpController
 */
class Index extends Common
{
    /**
     * 首页方法
     * @author : evalor <master@evalor.cn>
     */
    public function index()
    {
        // $user = new \App\Model\User();
        // $users = $user->getUsers();
        //
        $pool = PoolManager::getInstance()->getPool('App\Utility\MysqlPool'); // 获取连接池对象
        // $db = $pool->getObj();
        // $ret = $db->get('users');
        // var_dump($ret);
        // $pool->freeObj($db);
        go(function () use ($pool) {
            $db = $pool->getObj();
            if ($db) {
                $ret = $db->get('users');
//                var_dump($ret);
                $pool->freeObj($db);
                // var_dump($ret);
            } else {
                var_dump('db not available');
            }
        });

         $hmackey = 'ss';
         $payload = ['data' => 'data', 'exp' => time() + 10];
         // build expired token
         $token = jwt_encode($payload, $hmackey, 'HS256');
        // $decoded_token = jwt_decode($token, $hmackey, ['algorithm' => 'HS256']);

        $this->render('index', ['name' => $token]);
    }
}
